/* 获取用户信息相关封装 */
import store from '@/store';
import api from "@/api";
import { getToken } from '@/utils/auth'
import db from '@/utils/storage'

export const getUserInfo = ()=> {
    let userInfo = store.getters['app/getUserInfo'];
    if (Object.entries(userInfo).length<1) {
      userInfo = setUserInfo()
    }
    return userInfo;
};
export const setUserInfo = async() => {
  try{
    const gToken = getToken()
    let res = await api.app.getUserInfo({
      gToken
    });
    await store.dispatch('app/setUserInfo',res.data.user);
    return userInfo;
  }catch(e){
    return {};
  }
}

export const removeUserInfo = async() => {
    db.remove('userInfo')
    await store.dispatch('app/setUserInfo', {});
}
